package com.foreveross.taskservice.web.controller.task;

import javax.annotation.Resource;

import org.dayatang.domain.InstanceFactory;
import org.dayatang.querychannel.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.foreveross.taskservice.application.task.statsdetail.ITaskDetailApplication;
import com.foreveross.taskservice.application.task.statsdetail.vo.BaseTaskVO;
import com.foreveross.taskservice.infra.db.HBaseCellModel;
import com.foreveross.taskservice.infra.db.HBaseRowModel;
import com.foreveross.taskservice.web.controller.auth.BaseController;

@Controller
@RequestMapping("/task/TaskDetail")
public class TaskDetailController extends BaseController{
	@Resource(name="taskDetailApplicationImpl")
	private ITaskDetailApplication taskDetailApplication;
	
	@ResponseBody
//	@RequestMapping(params="method=detailByChannelIdAndTaskStatus")
	@RequestMapping("/detail")
	public Page detail(BaseTaskVO vo )throws Exception{
			@SuppressWarnings("rawtypes")
			Page page=taskDetailApplication.query(vo.getChannelId(),vo.getTaskStatus(),vo.getGrabDateStr(), vo.getPageLen(), vo.getPageIndex());
//			return "task/TaskDetail_detailStatusList";
		//加个日期来识别是否为历史数据
		return page;
	}

	@RequestMapping(value = "/sourceFile", produces = "text/html;charset=UTF-8")  
	public  String sourceFile(ModelMap modelMap, @RequestParam String id)throws Exception{
		HBaseRowModel rowModel = InstanceFactory.getInstance(com.foreveross.taskservice.infra.db.HbaseManager.class)
				.getOneRecord("CRAWL_PF_SOURCE_DATA", id);
		HBaseCellModel model = rowModel.lookupCell("CONTENTS", "CONTENTS");
		modelMap.put("result", model.getValue());
		return "task/TaskDetail_crawlTaskSource";
	}
}


